/**
 * Created by Administrator on 2016/11/16.
 */

/**
 * Created by IAN on 2016/10/14.
 */
$(function () {
    var sel = $.Params.create();
    sel.addParams("page",0);
    sel.addParams("rows",rows);
    getData();

    //查询
    $("#searchBtn").on("click",function(){
        var menuName = $("#searchVal").val().trim();
        if(menuName !=""){
            sel.addParams("menuName",menuName);
        }else{
            sel.addParams("menuName",undefined);
        }
        getData();
    })

    //添加事件
    $('#addDataBtn').on("click",function(){
        window.location.href="powerMenuAdd.html";
    });

    //删除事件
    $('#delBtn').on("click",function(){
        var params = getCheckData();
        if(params != "") {
            if(confirm("确定要删除吗！")){
                var del = $.Params.create();
                del.addParams("params", params)
                del.ajax(getIP() + "powerMenu/deletePowerMenu", function (data) {
                    if (data.success) {
                        alert("删除成功！");
                        getData();
                    }
                })
            }
        }else{
            alert("请至少选中一项");
        }
    });

    //获取数据
    function getData(){
        sel.addParams("parentId","0");
        getPageData(sel,getIP()+"powerMenu/getPowerMenuPage",function(data){
            if(data.success){
                var html = "";
                $.each(data.result, function(i,val) {
                    html+="<tr role='row'' class='even'>" +
                        "<td><input eid='"+val.id+"' onclick='getCheck(this)' type='checkbox' class='classOption'></td>" +
                        "<td class='sorting_1'>"+val.menuName+"</td>" +
                        "<td><a href='powerChildMenuList.html?parentId="+val.id+"'>查看子菜单</a></td>"+
                        "<td>"+val.updateTime+"</td>"+
                        "<td>"+val.code+"</td>"+
                        "<td><button type='button' class='btn btn-primary'  onclick='updateInfo(\""+val.id+"\")'>修改</button></td>" +
                        "</tr>";
                });
                $("#listContainer").html(html);
            }
        })
    }

});

//修改数据
function updateInfo (eid) {
    window.location.href="powerMenuUpdate.html?eid="+eid;
}

